const { getDateDiff } = require('../../utils/utils')
const { fetch, newFetch } = require('../../utils/fetch')

// components/hotitem/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        data: Object,
        isEdit: Boolean
    },

    /**
     * 组件的初始数据
     */
    data: {
        time: '',
        specificarea:'',
    },

    /**
     * 组件的方法列表
     */
    methods: {
        call(e) {
            wx.makePhoneCall({
                phoneNumber: this.data.data.pushPhone
            })
        },
        jump(e) {
            // wx.navigateTo({
            //     url: '/pages/indexDetails/index?id='+ e.currentTarget.dataset['id'],
            //     success: function(res) {
            //         // 通过eventChannel向被打开页面传送数据
            //     }
            // })
            if(wx.getStorageSync('specificarea')) {
                this.setData({
                  specificarea:wx.getStorageSync('specificarea')
                })
              }

              if(this.data.isEdit) {
                fetch(`wx/ad/${this.data.specificarea}/detail`, 'POST', {
                    id: e.currentTarget.dataset['id']
                  }).then(res => {
                    if(res) {
                        console.log(res, '数据善良大方')
                          wx.navigateTo({
                            url: '/pages/publishad/index?ediddata='+JSON.stringify(res)+'&editid='+res.id
                        })
                    }
                  })
              }
          
        },
    },
    attached: function() {
        if(!this.data.data) {
            return;
        }
        let time = this.data.data.createDate && getDateDiff(this.data.data.createDate)
        this.setData({
            time
        })
    }
})
